﻿#include "ndt_scan_window.h"
#include "ndt_scan_scene.h"
#include "ndt_scan_view.h"

namespace eintik::presentation::viewcore {

NdtScanWindow::NdtScanWindow(int type, int32_t group, QWidget *parent)
    : QMainWindow(parent)
{
    Type = static_cast<VIEW_TYPE>(type);

    setWindowFlags(Qt::Window | Qt::WindowTitleHint);
    createViewAndScene();

    // 默认不旋转
    scene->updateRulers();
}

void NdtScanWindow::createViewAndScene()
{
    auto id = -1;
    if (Type == VIEW_TYPE::A_SCAN) {
        id = 0;
    } else if (Type == VIEW_TYPE::S_SCAN) {
        id = 1;
    }  else if (Type == VIEW_TYPE::C_SCAN_0) {
        id = 2;
    } else if (Type == VIEW_TYPE::D_SCAN) {
        id = 3;
    } else {
        // do nothing,
        return;
    }
    auto s = new NdtScanSceneImpl();
    s->set_scan_type(id);
    auto v = new NdtScanViewImpl();
    v->setScene(s);
    scene = s;
    view = v;

    setCentralWidget(view);
    scene->setScanView(view);
    scene->setParent(this);
    scene->init();
}

void NdtScanWindow::setColorMap(VIEW_TYPE type, const QVector<QColor> &colorVector)
{
    scene->setColorMap(colorVector);
    view->setColorMap(colorVector);
}

void NdtScanWindow::updateScan()
{
    scene->updateScan(true);
}

NdtScanWindow::~NdtScanWindow()
{
    if (view) {
        delete view;
    }
    if (scene) {
        delete scene;
    }
}

}
